Hi Everyone!
I'm writing a web page in ASP.NET. I have some JavaScript, and I have a submit button with an onClick event.
Is it possible to call a method I created in ASP with JavaScript's onClick event?
Please reply SASP
Thanks in advance
home / developersection / forums / call asp.net function from javascript?
Hi Everyone!
I'm writing a web page in ASP.NET. I have some JavaScript, and I have a submit button with an onClick event.
Is it possible to call a method I created in ASP with JavaScript's onClick event?
Please reply SASP
Thanks in advance
AVADHESH PATEL
13-Feb-2013Hi Ankita!
There are three way to call asp.net function from JavaScript
i. In your code file (assuming you are using C# and .NET 2.0 or later) add the following Interface to your Page Class to make it look like
public partial class Default : System.Web.UI.Page, IPostBackEventHandler{}
ii. This should add (using Tab-Tab) this function to your code file:
public void RaisePostBackEvent(string eventArgument) { }
iii. In your onclick event in Javascript write the following code:
var pageId = '<%= Page.ClientID %>';
__doPostBack(pageId, argumentString);
This will call the 'RaisePostBackEvent' method in your code file with the 'eventArgument' as the 'argumentString' you passed from the Javascript. Now, you can call any other event you like.
That is 'underscore-underscore-doPostBack' ... And, there should be no space in that sequence... Somehow the WMD does not allow me to write to underscores followed by a character!